package com.example.home.attorney.activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.attorney.adapter.LawyerCardListAdapter;
import com.example.home.attorney.bean.LawyerCardListBean;
import com.example.home.tool.OKHttpTool;

public class LawyerListPage extends AppCompatActivity {
    private RecyclerView rcvList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lawyer_list_page);
        initView();
        getList();
    }


    private void getList() {
        OKHttpTool.doNetRequest("prod-api/api/lawyer-consultation/legal-expertise/list",
                OKHttpTool.GET,
                LawyerCardListBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        LawyerCardListBean lawyerCardListBean = (LawyerCardListBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                LawyerCardListAdapter lawyerCardListAdapter = new LawyerCardListAdapter(LawyerListPage.this, lawyerCardListBean.getRows());
                                rcvList.setAdapter(lawyerCardListAdapter);
                                GridLayoutManager gridLayoutManager = new GridLayoutManager(LawyerListPage.this, 4);
                                rcvList.setLayoutManager(gridLayoutManager);
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }


    private void initView() {

        rcvList = findViewById(R.id.rcv_list);

    }
}